package itsm.isperp.module.service.change;

import itsm.isperp.framework.service.BaseService;
import itsm.isperp.module.entity.change.ChgElementRelation;
import itsm.isperp.module.repository.change.ChgElementRelationMapper;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2014-7-21
 * 
 */
@Service
public class ChgElementRelationService extends BaseService<ChgElementRelation> {

	@Resource
	public ChgElementRelationMapper ChgElementRelationMapper;

	@Override
	public ChgElementRelationMapper getRepository() {
		return ChgElementRelationMapper;
	}
	@Autowired
	protected JdbcTemplate jdbcTemplate;
	
	public void deleteAllByfromId(String fromId)
	{
		String sql = "delete from CHG_ELEMENT_RELATION where from_id='"+fromId+"'";
		jdbcTemplate.execute(sql);
	}
	public void deleteAllByfromId(String fromId,String toType)
	{
		String sql = "delete from CHG_ELEMENT_RELATION where from_id='"+fromId+"' and to_type='"+toType+"'";
		jdbcTemplate.execute(sql);
	}
	
	public void deleteAllByFilter(String fromId,String toId,String toType)
	{
		String sql = "delete from CHG_ELEMENT_RELATION where from_id='"+fromId+"' and to_id='"+toId+"' and to_type='"+toType+"'";
		jdbcTemplate.execute(sql);
	}
	
	public void deleteAllByFilter(String fromId,String toId)
	{
		String sql = "delete from CHG_ELEMENT_RELATION where from_id='"+fromId+"' and to_id='"+toId+"'";
		jdbcTemplate.execute(sql);
	}
	
	public void deleteAllByFilter(String toId)
	{
		String sql = "delete from CHG_ELEMENT_RELATION where  to_id='"+toId+"'";
		jdbcTemplate.execute(sql);
	}

}
